package torres.ai;

import torres.entity.Avatar;
import torres.entity.NPC;
import torres.fileIO.BasicContainer;
import torres.fileIO.ClassContainer;
import torres.fileIO.Saveable;
import torres.map.World;


/**
 * @author Torres
 * AI of other non-player Entities
 */
public abstract class AI implements Saveable, Runnable{
	
	protected Avatar player;
	protected int range;
	
	/**
	 * Creates a new AI
	 */
	public AI() {
		 player = World.getInstance().getPlayer();
	}
	
	/**
	 * Defined behavior of AI
	 */
	public abstract void run();
	
	
	/**
	 * Runs all entities that use AI in separate threads
	 */
	public abstract void runAll();
	
	/**
	 * Adds an Entity that will use AI
	 * @param e Entity that uses AI
	 */
	public abstract void addEntity(NPC e);
	
	/**
	 * Removes AI from Entity
	 * @param e Entity that has AI
	 */
	public abstract void removeEntity(NPC e);
	
	/* (non-Javadoc)
	 * @see torres.fileIO.Saveable#save()
	 */
	public ClassContainer save() {
			ClassContainer curClass = new ClassContainer("AI");
			curClass.setName("AI");
			curClass.addProperty(new BasicContainer("range", range));
			return curClass;
	}

	/* (non-Javadoc)
	 * @see torres.fileIO.Saveable#load(torres.fileIO.ClassContainer)
	 */
	public void load(ClassContainer property) {
		player = World.getInstance().getPlayer();
		BasicContainer rangeCont = (BasicContainer)property.getProperty("range");
		range = Integer.parseInt((String)rangeCont.getValue());
	}
}
